package ArrayDemo;

import java.util.Arrays;

public class ArrayTestDemo {
    public static void main(String[] args) {
        char arr[][] = new char[4][];
        arr[0] = new char[]{'春', '眠', '不', '觉', '晓'};
        arr[1] = new char[]{'处', '处', '闻', '啼', '鸟'};
        arr[2] = new char[]{'夜', '来', '风', '雨', '声'};
        arr[3] = new char[]{'花', '落', '知', '多', '少'};

        System.out.println("........输出横板格式..........");
        for (int i = 0; i < arr.length; i++) { //输出行数
            for (int j = 0; j < arr[i].length; j++) {  //输出列数，列应该小于当前行的长度
                System.out.print(arr[i][j]);
            }
            if (i % 2 == 0) {
                System.out.println("。");
            } else {
                System.out.println("，");
            }
        }

        System.out.println(".........输出竖版格式...........");
        for (int j = 0; j < arr[0].length; j++) { //先输出列
            for (int i = 3; i >= 0; i--) {  //再输出行
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }
        System.out.println("。，。，");

        //用foreach语句遍历二维数组
        for (char a[] : arr) {
            for (char b : a) {
                System.out.print(b);
            }
            System.out.println();
        }

        //填充二维数组
        int arr1[] = new int[5];
        Arrays.fill(arr1, 13);
        for (int n = 0; n < arr1.length; n++) {
            System.out.println("第" + n + "个元素值是：" + arr1[n]);
        }

        //替换数组中的元素
        int arr3[] = {1, 7, 6, 4, 5, 6, 9, 6, 4, 5, 8};
        Arrays.fill(arr3, 3, 7, 0);
        for (int m = 0; m < arr3.length; m++) {
            if (arr3[m] == 0) {
                System.out.print("*");
            } else
                System.out.print(arr3[m]);
        }
        System.out.println();

        //对数组进行排序
        int arr4[] = new int[]{23, 67, 12, 2, 45};
        Arrays.sort(arr4);
        for (int temp : arr4) {
            System.out.print(temp + " ");
        }
        System.out.println();

        //复制数组
        int arr5[] = {1, 2, 3};
        int arr6[] = Arrays.copyOf(arr5, 6);
        char arr7[] = {'a', 'b', 'c', 'd', 'e'};
        char arr8[] = Arrays.copyOfRange(arr7, 1, 3);
        System.out.print("arr6数组: ");
        for (int temp1 : arr6) {
            System.out.print(temp1 + " ");
        }
        System.out.println();
        System.out.print("arr8数组：");
        for (char temp2 : arr8) {
            System.out.print(temp2 + " ");
        }
    }
}
